package ${modulePackageName}.${camelModelName}.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import com.zzx.core.constant.RetCode;
import com.zzx.core.util.JsonReturn;
import com.zzx.core.util.UUIDUtil;
import ${modulePackageName}.model.${modelName};
import ${modulePackageName}.${camelModelName}.service.${modelName}Service;
 /**
 * @ClassName: ${modelName}controller。
 * @Description: ${modelName}管理Controller
 * @author: ${authorName}
 *
 */
@RestController
@RequestMapping("/${camelModelName}/")
public class ${modelName}Controller {
	@Autowired
	private ${modelName}Service ${camelModelName}Service;
	@RequestMapping("${camelModelName}Info")
	public ModelAndView ${camelModelName}Info(${modelName} ${camelModelName}, HttpServletRequest request) {
		List<${modelName}> ${camelModelName}s = ${camelModelName}Service.select${modelName}ByCondition(${camelModelName});
		return new ModelAndView("privilege/${camelModelName}/${camelModelName}Info").addObject(
				"${camelModelName}List", ${camelModelName}s);
	}
	@RequestMapping("insert")
	public JsonReturn insert(${modelName} ${camelModelName}) {
		JsonReturn jsonReturn = new JsonReturn();
		// 设置ID
		${camelModelName}.setId(UUIDUtil.getId());
		int flag = ${camelModelName}Service.insert(${camelModelName});
		if (flag == 1) {
			jsonReturn.setRetcode(RetCode.OK_CODE);
			jsonReturn.setRetmsg("添加成功");
		} else {
			jsonReturn.setRetcode(RetCode.ERROR_CODE);
			jsonReturn.setRetmsg("添加失败");
		}
		return jsonReturn;
	}
	@RequestMapping("select${modelName}ById")
	public JsonReturn select${modelName}ById(String id,HttpServletRequest request) {
		JsonReturn jsonReturn = new JsonReturn();
		${modelName} ${camelModelName} = ${camelModelName}Service.select${modelName}ById(id);
		jsonReturn.setRetcode(RetCode.OK_CODE);
		jsonReturn.setRetmsg(${camelModelName});
		return jsonReturn;
	}
	@RequestMapping("edit")
	public JsonReturn edit(${modelName} ${camelModelName}) {
		JsonReturn jsonReturn = new JsonReturn();
		// 设置ID
		int flag = ${camelModelName}Service.update(${camelModelName});
		if (flag == 1) {
			jsonReturn.setRetcode(RetCode.OK_CODE);
			jsonReturn.setRetmsg("修改成功");
		} else {
			jsonReturn.setRetcode(RetCode.ERROR_CODE);
			jsonReturn.setRetmsg("修改失败");
		}
		return jsonReturn;
	}
	@RequestMapping("delete")
	public JsonReturn delete(String id) {
		JsonReturn jsonReturn = new JsonReturn();
		// 设置ID
		int flag = ${camelModelName}Service.delete(id);
		if (flag == 1) {
			jsonReturn.setRetcode(RetCode.OK_CODE);
			jsonReturn.setRetmsg("删除成功");
		} else {
			jsonReturn.setRetcode(RetCode.ERROR_CODE);
			jsonReturn.setRetmsg("删除失败");
		}
		return jsonReturn;
	}
}